﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Pomelo.EntityFrameworkCore.MySql;
using System;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;

namespace EFCoreDemo
{
    class Program
    {
        private const string CONNECT_STR = "server=localhost;database=test;user=root;pwd=123456789;SslMode=none;Allow User Variables=True;AllowLoadLocalInfile=true";
        static void Main(string[] args)
        {
            var builder = CreateHostBuilder(args).Build();
            builder.Run();
        }

        /// <summary>
        /// CreateHostBuilder
        /// </summary>
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration(confBuilder =>
                {

                })
                .ConfigureServices(services =>
                {
                    services.AddTransient<IUserRepository, UserRepository>();
                    services.AddTransient<IUserService, UserService>();

                    services.AddDbContext<MyDbContext>(optionsBuilder =>
                    {
                        optionsBuilder.UseMySql(CONNECT_STR, MySqlServerVersion.LatestSupportedServerVersion, mysqlOption =>
                          {

                          });
                        optionsBuilder.UseBatchEF_MySQLPomelo();
                    });
                    services.AddHostedService<MyHostService>();
                });
        }
    }
}
